package com.sc.nft.admin.controller;

import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.dto.IdRequest;
import com.sc.nft.entity.dto.*;
import com.sc.nft.entity.vo.tradingPool.*;
import com.sc.nft.service.TradingPoolConfigService;
import com.sc.nft.service.TradingPoolOrderService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 刘国航
 * @desc 交易池
 * @since 2024/10/28 10:11
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/tradingPool")
@Api(tags = "交易池")
public class TradingPoolController {

    private final TradingPoolConfigService tradingPoolConfigService;
    private final TradingPoolOrderService tradingPoolOrderService;

    @ApiOperation(value = "交易池分页查询", notes = "交易池分页查询", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/confPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<TradingPoolVO> confPage(@RequestBody TradingPoolPageDTO request) {
        return PageResult.success(tradingPoolConfigService.confPage(request.toMp(), request.getDaoId()));
    }

    @ApiOperation(value = "修改交易池", notes = "修改交易池", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateConf", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<Boolean> updateConf(@RequestBody @Valid TradingPoolUpdateConfDTO request) {
        return Result.success(tradingPoolConfigService.updateConf(request, Boolean.TRUE));
    }

    @ApiOperation(value = "交易池详情", notes = "修改交易池", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/confDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<TradingPoolVO> confDetail(@RequestBody @Valid IdRequest request) {
        return Result.success(tradingPoolConfigService.confDetail(request.getId()));
    }

    @ApiOperation(value = "更新销毁配置", notes = "更新销毁配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateDestructionConf", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<Boolean> updateDestructionConf(@RequestBody @Valid TradingPoolDestructionConfDTO request) {
        return Result.success(tradingPoolConfigService.updateDestructionConf(request));
    }

    @ApiOperation(value = "销毁配置详情", notes = "销毁配置详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/destructionConfDetail", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<TradingPoolDestructionConfVO> destructionConfDetail(@RequestBody @Valid IdRequest request) {
        return Result.success(tradingPoolConfigService.destructionConfDetail(request.getId()));
    }

    @ApiOperation(value = "交易池开关", notes = "交易池开关", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateConfStatus", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<Boolean> updateConfStatus(@RequestBody @Valid TradingPoolUpdateStatusDTO request) {
        return Result.success(tradingPoolConfigService.updateConfStatus(request.getId(), request.getStatus()));
    }

    @ApiOperation(value = "删除交易池", notes = "删除交易池", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteConf", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<Boolean> deleteConf(@RequestBody @Valid IdRequest request) {
        return Result.success(tradingPoolConfigService.deleteConf(request.getId()));
    }

    @ApiOperation(value = "库存加减", notes = "库存加减", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/confAdjustStock", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<Boolean> confAdjustStock(@RequestBody @Valid TradingPoolConfAdjustStockDTO request) {
        return Result.success(tradingPoolConfigService.confAdjustStock(request));
    }

    @ApiOperation(value = "设置分润模版", notes = "设置分润模版", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/confShareProfitPanel", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<Boolean> confShareProfitPanel(@RequestBody @Valid TradingPoolConfShareProfitPanelDTO request) {
        return Result.success(tradingPoolConfigService.confShareProfitPanel(request));
    }

    @ApiOperation(value = "获取分润模版", notes = "获取分润模版", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getShareProfitPanel", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<TradingPoolSharePanelVO> getShareProfitPanel(@RequestBody @Valid IdRequest request) {
        return Result.success(tradingPoolConfigService.getShareProfitPanel(request.getId()));
    }

    @ApiOperation(value = "金额加减", notes = "金额加减", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/confAdjustAmount", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<Boolean> confAdjustAmount(@RequestBody @Valid TradingPoolConfAdjustAmountDTO request) {
        return Result.success(tradingPoolConfigService.confAdjustAmount(request));
    }

    @ApiOperation(value = "获取市值账号", notes = "获取市值账号", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/marketAccount", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<TradingPoolMarketAccountVO>> marketAccount(@RequestBody @Valid TradingPoolMarketAccountDTO request) {
        return Result.success(tradingPoolConfigService.marketAccount(request.getDaoId()));
    }

    @ApiOperation(value = "交易池记录", notes = "交易池记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/changeLogPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<TradingPoolChangeLogVO> changeLogPage(@RequestBody @Valid TradingPoolChangeLogDTO request) {
        return PageResult.success(tradingPoolConfigService.changeLogPage(request));
    }

    @ApiOperation(value = "交易记录", notes = "交易记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/orderPage", produces = MediaType.APPLICATION_JSON_VALUE)
    public PageResult<TradingPoolOrderPageVO> orderPage(@RequestBody TradingPoolOrderDTO request) {
        return PageResult.success(tradingPoolOrderService.orderPage(request));
    }

    @ApiOperation(value = "查询可用数量", notes = "查询可用数量", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/queryUsable", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<TradingPoolQueryUsableVO> queryUsable(@RequestBody @Valid TradingPoolQueryUsableDTO request) {
        return PageResult.success(tradingPoolConfigService.queryUsable(request));
    }

}
